package com.tuoyu.peopletest.adapter;//package com.stresscude.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.tuoyu.peopletest.R;
import com.tuoyu.peopletest.entity.UserTestAllBean;
import com.tuoyu.peopletest.scinterface.OnItemDataListener;
import com.tuoyu.peopletest.utils.SCTimeUtils;
import com.tuoyu.peopletest.utils.SCUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 用户测试结果列表
 */
public class UserTestListAdapter extends RecyclerView.Adapter<UserTestListAdapter.MyMCHolder> {
    public String TAG = this.getClass().getSimpleName();
    public OnItemDataListener<UserTestAllBean> mListener;

    private List<UserTestAllBean> mDatas;
    private Context mContext;
    private boolean isOnClick;


    public UserTestListAdapter(Context mContext, List<UserTestAllBean> mDatas, boolean isOnClick) {
        this.mDatas = mDatas;
        this.mContext = mContext;
        this.isOnClick = isOnClick;
    }


    @Override
    public MyMCHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_test_list, null);
        MyMCHolder holder = new MyMCHolder(itemView);

        if (isOnClick) {
            holder.itemView.setOnClickListener((v) -> {
                int position = (int) v.getTag(R.id.sc_id_recycleview_item);
                if (mListener != null) {
                    mListener.onItemData(mDatas.get(position), position);
                }

            });
        }

        return holder;
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public void onBindViewHolder(MyMCHolder holder, int position) {
        holder.itemView.setTag(R.id.sc_id_recycleview_item, position);
        UserTestAllBean bean = mDatas.get(position);
        if (position % 2 == 0) {
            holder.vItemMain.setBackgroundResource(R.color.white);
        } else {
            holder.vItemMain.setBackgroundResource(R.color.sc_c_bg_gray_d8_39);
        }

//血浆同型\n半胱氨酸水平
//        if (bean.xjtxbasspBean != null) {
//            holder.tvXjtsasp.setText("" + bean.xjtxbasspBean.value);
//        } else {
//            holder.tvXjtsasp.setText("");
//        }


    }

    public void setItemClickListener(OnItemDataListener<UserTestAllBean> listener) {
        this.mListener = listener;
    }

    public void addDatas(ArrayList<UserTestAllBean> list) {
        if (list != null) {
            mDatas.addAll(list);
        }
    }

    public void upDatas(ArrayList<UserTestAllBean> list) {
        mDatas.clear();
        if (list != null) {
            mDatas.addAll(list);
        }

        notifyDataSetChanged();
    }

    static class MyMCHolder extends RecyclerView.ViewHolder {
        public View vItemMain;
        public TextView tvDate;
        public TextView tvBreathRate;
        public TextView tvSelectRection;
        public TextView tvMaxOyg;
        public TextView tvMemorySize;
        public TextView tvXjtsasp;

        public ImageView vHrvOk;
        public TextView tvAmylase;
        public TextView tvStressOwnTable;
        //应激损伤
        public TextView tvStressInjure;

        public MyMCHolder(@NonNull View itemView) {
            super(itemView);
            vItemMain = itemView.findViewById(R.id.v_item_main);
            tvDate = itemView.findViewById(R.id.v_title_data);


            tvBreathRate = itemView.findViewById(R.id.v_title_breath_rate);
            tvSelectRection = itemView.findViewById(R.id.v_title_select_rection);
            tvMaxOyg = itemView.findViewById(R.id.v_title_max_oyg);
            tvMemorySize = itemView.findViewById(R.id.v_title_memory_size);
            vHrvOk = itemView.findViewById(R.id.v_hrv_ok);
            tvAmylase = itemView.findViewById(R.id.v_title_amylase);
            tvXjtsasp = itemView.findViewById(R.id.v_title_xjtsasp);
            tvStressOwnTable = itemView.findViewById(R.id.v_title_stress_own_table);
            tvStressInjure = itemView.findViewById(R.id.v_title_stress_injure);
        }
    }
}
